package com.zjun.demo.experimentaldemo.scale_seekBar

import android.graphics.Color
import android.view.View
import android.widget.SeekBar
import com.zjun.demo.experimentaldemo.R
import com.zjun.demo.experimentaldemo.base.BaseActivity
import com.zjun.demo.experimentaldemo.databinding.ActivityScaleSeekBarBinding
import kotlin.math.roundToInt

/**
 * 带刻度的seekbar
 */
class ScaleSeekBarActivity : BaseActivity<ActivityScaleSeekBarBinding>(), SeekBar.OnSeekBarChangeListener {

    override fun getLayoutId(): Int = R.layout.activity_scale_seek_bar

    override fun initialize() {

        //设置相关属性值
        mBinding.seekBar.setDrawStyle(1)
        mBinding.seekBar.setCount(9)
        mBinding.seekBar.setDrawText(false)
        mBinding.seekBar.setAllColor(Color.WHITE,Color.GRAY)
        mBinding.seekBar.setShowTopOfThumb(true)
        mBinding.seekBar.setOnSeekBarChangeListener(this)

        mBinding.simpleScaleSeekBarView.setDrawStyle(2)
        mBinding.simpleScaleSeekBarView.setCount(9)
        mBinding.simpleScaleSeekBarView.setRulerColor(Color.parseColor("#FF01112E"))
    }


    override fun onClick(v: View) {
        when(v.id){


        }
    }

    @Override
    override fun onProgressChanged( seekBar:SeekBar, i:Int,b:Boolean) {
        if (seekBar.progress <100){
            seekBar.progress = ((seekBar.progress / 10).toDouble().roundToInt() *10+5).toInt()
        }else {
            seekBar.progress = 105
        }
        mBinding.tvShow.text = "${(seekBar.progress -5)/10}"
    }

    @Override
    override fun onStartTrackingTouch(seekBar:SeekBar) {

    }

    @Override
    override fun onStopTrackingTouch(seekBar:SeekBar) {

    }


}